<?php

namespace app\admin\controller;

use app\admin\logic\MessageNotificationLogic;
use support\Request;
use support\Response;

/**
 * 消息通知控制器
 */
class MessageNotificationController extends BaseController
{
    /**
     * 构造
     */
    public function __construct()
    {
        $this->logic = new MessageNotificationLogic();
        parent::__construct();
    }

    /**
     * 数据列表
     * @param Request $request
     * @return Response
     */
    public function index(Request $request) : Response
    {
        $where = $request->more([
            ['title', ''],
            ['type_id', ''],
            ['create_time', []]
        ]);
        $query = $this->logic->search($where)->with(['type' => function($query) {
            $query->visible(['id', 'name']);
        }, 'company' => function($query) {
            $query->visible(['id', 'name']);
        }])->order('id', 'desc');
        $list = $this->logic->getList($query);
        foreach ($list['data'] as $key => $value) {
            $list['data'][$key]['desc'] = cn_substr(strip_tags($value['content'] ?? ''), 200);
            $list['data'][$key]['company_id'] = !empty($value['company']) ? array_column($value['company'], 'id') : [];
        }
        return $this->success($list);
    }


    
}
